package com.auxgroup.smarthome.job;

import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.event.JobEventConfiguration;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * Created by niuGuangzhe on 2017/8/24.
 */
//@Configuration
public class CatchMesSnModelMappingScheduler {
    private Logger log= LoggerFactory.getLogger(CatchMesSnModelMappingScheduler.class);

    @Resource
    private ZookeeperRegistryCenter regCenter;

    @Resource
    private JobEventConfiguration jobEventConfiguration;

    @Bean
    public JobScheduler catchMesSnSimpleJobScheduler(final CatchMesSnModelMappingJob catchMesSnModelMappingJob,
                                           @Value("${mesCatchJob.cron}") final String cron,
                                           @Value("${mesCatchJob.shardingTotalCount}") final int shardingTotalCount,
                                           @Value("${mesCatchJob.shardingItemParameters}") final String shardingItemParameters) {
        JobCoreConfiguration jobCoreConfiguration = JobCoreConfiguration.newBuilder("拉取Mes数据任务",
                cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).build();
        SimpleJobConfiguration simpleJobConfiguration = new SimpleJobConfiguration(jobCoreConfiguration, catchMesSnModelMappingJob.getClass().getCanonicalName());
        LiteJobConfiguration liteJobConfiguration = LiteJobConfiguration.newBuilder(simpleJobConfiguration).overwrite(true).build();
        log.info(liteJobConfiguration.toString());
        return new SpringJobScheduler(catchMesSnModelMappingJob, regCenter, liteJobConfiguration, jobEventConfiguration);
    }
}
